<%@page import="entities.User"%>
<%@page import="java.util.TreeMap"%>
<%@page import="entities.Article"%>
<%@page import="entities.Category"%>
<%@page import="java.util.List"%>
<%
TreeMap check = (TreeMap) request.getAttribute("check");
Article article = (Article) request.getAttribute("article");
List<Category> categories = (List<Category>) request.getAttribute("categories");
String sucess = (String)request.getAttribute("success");
User user = (User) request.getAttribute("user_logged_in");
%>
<jsp:include page="/demo/layouts/header.jsp" />

		<div class="dir">
			<a href="/home">Home</a>
		</div>
			
		<br />
		<div class="submit-form">
			<% if (sucess != null) { %>
			<div class="s-message">
				<%=sucess %>
			</div>
			<% } %>
			<form action="" method="post">
			<table width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<td colspan="2"><div class="title-form">Submit Articles</div></td>
					</tr>
				</thead>
				<tbody>
					<% if (user == null) { %>
					<tr>
						<td width="30%">
							Author Name
						</td>
						<td>
							<input type="text" name="name" value="<%=article.getAuthorName() %>">
							<% if (check.get("name") != null) { %>
							<div class="error"><%=check.get("name") %></div>
							<% } %>
						</td>
					</tr>
					<tr>
						<td width="30%">
							Author Email
						</td>
						<td>
							<input type="text" name="email" value="<%=article.getEmail() %>">
							<% if (check.get("email") != null) { %>
							<div class="error"><%=check.get("email") %></div>
							<% } %>
						</td>
					</tr>
					<% } else { %>
					<tr>
						<td width="30%">
							Author Id
						</td>
						<td>
							<input type="text" name="creator" value="<%=article.getCreator() %>">
							<% if (check.get("creator") != null) { %>
							<div class="error"><%=check.get("creator") %></div>
							<% } %>
						</td>
					</tr>
					<% } %>
					<tr>
						<td width="30%">
							Title Article
						</td>
						<td>
							<input type="text" name="title" value="<%=article.getTitle() %>">
							<% if (check.get("title") != null) { %>
							<div class="error"><%=check.get("title") %></div>
							<% } %>
						</td>
					</tr>
					<tr>
						<td width="30%">
							Category
						</td>
						<td>
							<select name="category">
								<% for (Category category : categories) { %>
								<option value="<%=category.getId()%>" <%=category.getId().equalsIgnoreCase(article.getCategory()) ? "selected=\"selected\"" : "" %>><%=category.getName() %></option>
								<% } %>
							</select>
							<% if (check.get("category") != null) { %>
							<div class="error"><%=check.get("category") %></div>
							<% } %>
						</td>
					</tr>
					<tr>
						<td width="30%">
							Description
						</td>
						<td>
							<textarea rows="3" cols="7" class="" name="description"><%=article.getDescription() %></textarea>
							<% if (check.get("description") != null) { %>
							<div class="error"><%=check.get("description") %></div>
							<% } %>
						</td>
					</tr>
					<tr>
						<td width="30%">
							Content
						</td>
						<td>
							<textarea rows="3" cols="7" class="" name="content"><%=article.getContent() %></textarea>
							<% if (check.get("content") != null) { %>
							<div class="error"><%=check.get("content") %></div>
							<% } %>
						</td>
					</tr>
				</tbody>
				<tfoot>
					<tr>
						<td></td>
						<td>
							<input type="hidden" name="language" value="en" >
							<button type="submit">Submit</button>
						</td>
					</tr>
				</tfoot>
			</table>
			</form>
		</div>

<jsp:include page="/demo/layouts/footer.jsp" />